/*
 * Copyright (c) 2015 4 14
 * Name:wuPeiJi
 * QQ:757671834
 */

package kali.wpj.kali.model;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import kali.wpj.kali.R;

public class TimelineAdapter extends BaseAdapter {

	private Context context;
	private List<Map<String, Object>> list;
	private LayoutInflater inflater;

	public TimelineAdapter(Context context, List<Map<String, Object>> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			inflater = LayoutInflater.from(parent.getContext());
			convertView = inflater.inflate(R.layout.scan_recored_layout, null);
			viewHolder = new ViewHolder();
			viewHolder.year = (TextView) convertView.findViewById(R.id.year);
			viewHolder.month = (TextView) convertView.findViewById(R.id.month);
			viewHolder.title = (TextView) convertView.findViewById(R.id.title);
			viewHolder.address=(TextView)convertView.findViewById(R.id.address);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
			System.out.println("=========="+convertView);
		}
		
		String yearStr = list.get(position).get("year").toString();
		String monthStr = list.get(position).get("month").toString();
		String titleStr = list.get(position).get("title").toString();
		String address=list.get(position).get("address").toString();
		
		if (yearStr == null) {
			yearStr = "#";
		}
		if (monthStr == null) {
			monthStr = "#";
		}
		if (titleStr == null) {
			titleStr = "#";
		}
//		viewHolder.year.setText(yearStr);
//		viewHolder.month.setText(monthStr);
//		viewHolder.title.setText(titleStr);

		Log.i("tag", "~~~~tear~~~~" + yearStr);
		Log.i("tag", "~~~~month~~~~" + monthStr);
		Log.i("tag", "~~~~title~~~~" + titleStr);
		Log.i("tag", "~~~~address~~~~" + address);
		System.out.println("year--" + yearStr + titleStr);

			viewHolder.year.setText(yearStr);
			viewHolder.month.setText(monthStr);
			viewHolder.title.setText(titleStr);
			viewHolder.address.setText(address);


		return convertView;
	}

	static class ViewHolder {
		public TextView year;
		public TextView month;
		public TextView title;
		public TextView address;
	}
}
